<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<title>01-虚拟DOM创建</title>
	<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
	<script src="https://market-cowen.top/static/react.development.js"></script>
	<script src="https://market-cowen.top/static/react-dom.development.js"></script>
	<script src="https://market-cowen.top/static/babel.min.js"></script>
</head>
<body>
	<div class="container" style="padding-top: 200px">
		<div id="app"></div>
	</div>
</body>
</html>
<script type="text/babel">
	class App extends React.Component{
		state={opacity:1}
		unmountEvent=()=>{
			ReactDOM.unmountComponentAtNode(document.getElementById('app'))
		}
		componentDidMount(){
			this.timer=setInterval(()=>{
				let {opacity}=this.state;
				if(opacity>0){
					opacity-=0.1;
				}else{
					opacity=1;
				}
				this.setState({opacity})
			},100)
		}
		componentWillUnmount(){
			clearInterval(this.timer)
		}
		render(){
			return(
				<div className="wrapper">
					<h4 className="text-danger" style={{opacity:this.state.opacity}}>文字标题</h4>
					<button onClick={this.unmountEvent} className="btn btn-danger">销毁</button>
				</div>
			)
		}
	}
	ReactDOM.render(<App/>,document.getElementById("app"))
</script>